package com.epower.bo.epowerword.impl;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.epower.base.BaseBO;
import com.epower.bo.epowersentence.EpowerSentenceService;
import com.epower.bo.epowerword.EpowerWordService;
import com.epower.dao.epowerword.EpowerWordDAO;
import com.epower.dataobject.EpowerWordDO;
import java.util.List;

/***
 * BO层实现类
 * 
 * @author QuickDev
 */
@Scope("singleton")
@Component("epowerWordBO")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EpowerWordServiceImpl extends BaseBO implements EpowerWordService {

    private EpowerWordDAO epowerWordDAO;

    private EpowerSentenceService epowerSentenceBO;
    
    /***
     * 
     */
    @Override
    public EpowerWordDO getEpowerWordByOption(EpowerWordDO epowerWord) {
        return epowerWordDAO.getEpowerWordByOption(epowerWord);
    }

    /***
     * 
     */
    @Override
    public List<EpowerWordDO> getEpowerWordListByOption(EpowerWordDO epowerWord) {
        return epowerWordDAO.getEpowerWordListByOption(epowerWord);
    }

    @Override
    public List<EpowerWordDO> getEpowerWordListPageByOption(EpowerWordDO epowerWord) {
        int totalItem = getEpowerWordCountByOption(epowerWord);
        epowerWord.setTotalItem(totalItem);
        return epowerWordDAO.getEpowerWordListByOption(epowerWord);
    }

    /***
     * 
     */
    @Override
    public EpowerWordDO getEpowerWordById(Integer id) {
        return epowerWordDAO.getEpowerWordById(id);
    }

    /***
     * 
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean deleteEpowerWordById(Integer id) {
        return epowerWordDAO.deleteEpowerWordById(id);
    }

    /***
     * 
     */
    @Override
    public Integer getEpowerWordCountByOption(EpowerWordDO epowerWord) {
        return epowerWordDAO.getEpowerWordCountByOption(epowerWord);
    }

    /***
     * 
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean updateEpowerWordByOption(EpowerWordDO epowerWord) {
        return epowerWordDAO.updateEpowerWordByOption(epowerWord);
    }

    /***
     * 
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer addEpowerWord(EpowerWordDO epowerWord) {
        try {
            Integer id = epowerWordDAO.addEpowerWord(epowerWord);
            return id;
        } catch (Exception e) {
            throw new RuntimeException("service is error");
        }
    }

    @Override
    public EpowerWordDO getWordByBookid(int bookid, int index) {
    	EpowerWordDO word = epowerWordDAO.getWordByBookid(bookid, index);
    	if(word!=null){
    		word.setEpowerSentenceBO(epowerSentenceBO);
    	}
        return word;
    }

    @Override
    public int getWordCountByBookid(int bookid) {
        // TODO Auto-generated method stub
        return epowerWordDAO.getWordCountByBookid(bookid);
    }
    
    /***
     * @getter setter
     */
    public EpowerWordDAO getEpowerWordDAO() {
        return epowerWordDAO;
    }

    @Resource
    public void setEpowerWordDAO(EpowerWordDAO epowerWordDAO) {
        this.epowerWordDAO = epowerWordDAO;
    }

	public EpowerSentenceService getEpowerSentenceBO() {
		return epowerSentenceBO;
	}

	public void setEpowerSentenceBO(EpowerSentenceService epowerSentenceBO) {
		this.epowerSentenceBO = epowerSentenceBO;
	}

}
